/*
 * SQLErrorDialog.java
 *
 * Created on 1. März 2008, 11:51
 */

package com.googlecode.oskis.library.db;

/**
 * SQLErrorDialog ist ein Dialog zur verständlichen Anzeige von SQL Fehlermeldungen
 * im Konstruktor wird die Exception sowie ein String übergeben, der das DBMS bezeichnet.
 * Der Dialog zeigt dann den Fehlertext und den Versuch einer Interpretation des Fehlercodes an.
 * @author  thomas
 */
public class SQLErrorDialog extends javax.swing.JDialog {
    
    /** Creates new form SQLErrorDialog */
    public SQLErrorDialog(java.awt.Frame parent, String dbms,java.sql.SQLException e,String SQL) {
        super(parent, true);
        initComponents();
        int errorcode=e.getErrorCode();
        String errortext=e.toString();
        txtErrorcode.setText(String.valueOf(errorcode));
        txtErrortext.setText(errortext);
        txtSQL.setText(SQL.replace("\\s+", " "));
        if (dbms.equals("PG")) {
            txtDBMS.setText("Postgresql");
        }
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lblDBMS = new javax.swing.JLabel();
        txtDBMS = new javax.swing.JTextField();
        lblErrortext = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtErrortext = new javax.swing.JTextArea();
        lblErrorcode = new javax.swing.JLabel();
        txtErrorcode = new javax.swing.JTextField();
        lblBedeutung = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        txtBedeutung = new javax.swing.JTextArea();
        btnOK = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        txtSQL = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("SQL Fehlermeldung");

        lblDBMS.setText("Datenbank");

        txtDBMS.setBackground(new java.awt.Color(255, 255, 102));

        lblErrortext.setText("Fehlertext");

        txtErrortext.setBackground(new java.awt.Color(255, 255, 102));
        txtErrortext.setColumns(20);
        txtErrortext.setEditable(false);
        txtErrortext.setLineWrap(true);
        txtErrortext.setRows(5);
        jScrollPane1.setViewportView(txtErrortext);

        lblErrorcode.setText("Fehlercode");

        txtErrorcode.setBackground(new java.awt.Color(255, 255, 51));

        lblBedeutung.setText("Bedeutung");

        txtBedeutung.setBackground(new java.awt.Color(204, 255, 51));
        txtBedeutung.setColumns(20);
        txtBedeutung.setLineWrap(true);
        txtBedeutung.setRows(5);
        txtBedeutung.setWrapStyleWord(true);
        jScrollPane2.setViewportView(txtBedeutung);

        btnOK.setText("OK");

        txtSQL.setBackground(new java.awt.Color(153, 255, 0));
        txtSQL.setColumns(20);
        txtSQL.setLineWrap(true);
        txtSQL.setRows(5);
        txtSQL.setWrapStyleWord(true);
        jScrollPane3.setViewportView(txtSQL);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnOK, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblErrortext)
                            .addComponent(lblDBMS)
                            .addComponent(lblErrorcode)
                            .addComponent(lblBedeutung))
                        .addGap(60, 60, 60)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 333, Short.MAX_VALUE)
                            .addComponent(txtErrorcode, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 333, Short.MAX_VALUE)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 333, Short.MAX_VALUE)
                            .addComponent(txtDBMS, javax.swing.GroupLayout.DEFAULT_SIZE, 333, Short.MAX_VALUE)
                            .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 333, Short.MAX_VALUE))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblDBMS)
                    .addComponent(txtDBMS, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblErrortext)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblErrorcode)
                            .addComponent(txtErrorcode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(8, 8, 8)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnOK))
                    .addComponent(lblBedeutung))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    

    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnOK;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JLabel lblBedeutung;
    private javax.swing.JLabel lblDBMS;
    private javax.swing.JLabel lblErrorcode;
    private javax.swing.JLabel lblErrortext;
    private javax.swing.JTextArea txtBedeutung;
    private javax.swing.JTextField txtDBMS;
    private javax.swing.JTextField txtErrorcode;
    private javax.swing.JTextArea txtErrortext;
    private javax.swing.JTextArea txtSQL;
    // End of variables declaration//GEN-END:variables
    
}
